package com.pb.metadata.controller;

import com.pb.infra.oth.entity.common.Result;
import com.pb.metadata.service.CalendarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 节假日管理
 * @author liaohaoyuan
 * @date 2022.4.3
 */
@RequestMapping("v1/metadata/calendar")
@RestController
public class CalendarController {

    @Resource
    private CalendarService calendarService;

    /**
     * 查询假期数据
     * @param paramMap
     * @return
     */
    @GetMapping("getHoliday")
    public Result getHoliday(@RequestParam Map<String,Object> paramMap) {
        try{
            List<Map<String,Object>> list =calendarService.getHoliday(paramMap);
            return Result.ok(list);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(),e);
        }
    }

    /**
     * 手动设置假期数据
     * @param paramMap
     * @return
     */
    @PostMapping("saveHoliday")
    public Result saveHoliday(@RequestBody Map<String,Object> paramMap) {
        try{
            calendarService.saveHoliday(paramMap);
            return Result.ok("保存成功");
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(),e);
        }
    }

    /**
     * 初始化年份假期数据
     * @param paramMap
     * @return
     */
    @PostMapping("initYearsData")
    public Result initYearsData(@RequestBody Map<String,Object> paramMap) {
        try{
            String str = calendarService.initYearsData(paramMap);
            return Result.ok(str);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(),e);
        }
    }

    /**
     * 获取初始化节日类型清单
     * @param paramMap
     * @return
     */
    @PostMapping("getTableData")
    public Result getTableData(@RequestBody Map<String,Object> paramMap) {
        try{
            List<Map<String,Object>> list =calendarService.getTableData(paramMap);
            return Result.ok(list);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(),e);
        }
    }

    /**
     * 获取码值
     * @param paramMap
     * @return
     */
    @GetMapping("getCodeTypeData")
    public Result getCodeTypeData(@RequestParam Map<String,Object> paramMap){
        try{
            List<Map<String,Object>> list =calendarService.getCodeTypeData(paramMap);
            return Result.ok(list);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(),e);
        }
    }

    /**
     * 获取码值
     * @param paramMap
     * @return
     */
    @GetMapping("getCodeTypeData2")
    public Result getCodeTypeData2(@RequestParam Map<String,Object> paramMap){
        try{
            List<Map<String,Object>> list =calendarService.getCodeTypeData2(paramMap);
            return Result.ok(list);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(),e);
        }
    }

}
